/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.clarice.homechef.service;

import com.clarice.homechef.dao.MealDao;
import com.clarice.homechef.domain.Chef;
import com.clarice.homechef.domain.Meal;
import com.clarice.homechef.domain.MealReview;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Akshay Velhal
 */
@Service
public class MealServiceImpl implements MealService{

    @Autowired
    MealDao mealDao;
    
    @Autowired
    ChefService chefService;
    
    @Override
    public Meal createNewMeal(Meal meal, String username) throws Exception {
        Chef chef = chefService.getChefByEmail(username);
        meal.setChefId(chef.getChefId());
        return mealDao.createNewMeal(meal, username);
    }

    @Override
    public Meal getMeal(int mealId) throws Exception {
        Meal meal = mealDao.getMeal(mealId);
        Chef chef = chefService.getChefById(meal.getChefId());
        meal.setChefAddress(chef.getAddress());
        meal.setChefName(chef.getName());
        return meal;
    }

    @Override
    public List<Meal> getMeals(String date) throws Exception {
        return mealDao.getMeals(date);
    }

    @Override
    public List<Meal> getPopularDishes(int mealId) throws Exception {
        return mealDao.getPopularDishes(mealId);
    }

    @Override
    public List<Meal> getLatestTrendingDishes(int mealId) throws Exception {
        return mealDao.getLatestTrendingDishes(mealId);
    }

    @Override
    public void addMealReview(int mealId, MealReview mealReview) throws Exception {
        mealDao.addMealReview(mealId, mealReview);
    }
    
}
